// 模拟日志数据
export const mockLogData = [
  {
    Id: 1,
    SystemName: '捷豹路虎ESP系统',
    Device: 'ECU_001',
    Group1: '控制模块',
    Group2: '安全系统',
    Group3: 'ESP功能',
    UserName: 'admin',
    UserLevel: '管理员',
    OldEvent: '系统正常',
    NewEvent: '系统启动',
    Description: '系统正常启动',
    DateTime: '2023-11-01 08:00:00'
  },
  {
    Id: 2,
    SystemName: '捷豹路虎ESP系统',
    Device: 'ECU_002',
    Group1: '传感器',
    Group2: '轮速传感器',
    Group3: '左前轮',
    UserName: 'user1',
    UserLevel: '操作员',
    OldEvent: '正常',
    NewEvent: '警告',
    Description: '左前轮速传感器信号异常',
    DateTime: '2023-11-01 08:15:30'
  },
  {
    Id: 3,
    SystemName: '捷豹路虎ESP系统',
    Device: 'ECU_001',
    Group1: '控制模块',
    Group2: '安全系统',
    Group3: 'ESP功能',
    UserName: 'admin',
    UserLevel: '管理员',
    OldEvent: '系统启动',
    NewEvent: '系统配置更新',
    Description: 'ESP系统配置参数更新',
    DateTime: '2023-11-01 09:30:45'
  },
  {
    Id: 4,
    SystemName: '捷豹路虎ESP系统',
    Device: 'ECU_003',
    Group1: '执行器',
    Group2: '制动系统',
    Group3: '右后轮',
    UserName: 'user2',
    UserLevel: '操作员',
    OldEvent: '正常',
    NewEvent: '故障',
    Description: '右后轮制动压力传感器故障',
    DateTime: '2023-11-01 10:45:12'
  },
  {
    Id: 5,
    SystemName: '捷豹路虎ESP系统',
    Device: 'ECU_002',
    Group1: '传感器',
    Group2: '轮速传感器',
    Group3: '左前轮',
    UserName: 'user1',
    UserLevel: '操作员',
    OldEvent: '警告',
    NewEvent: '正常',
    Description: '左前轮速传感器信号恢复正常',
    DateTime: '2023-11-01 11:20:33'
  },
  {
    Id: 6,
    SystemName: '捷豹路虎ESP系统',
    Device: 'ECU_004',
    Group1: '传感器',
    Group2: '转向角度传感器',
    Group3: '方向盘',
    UserName: 'admin',
    UserLevel: '管理员',
    OldEvent: '正常',
    NewEvent: '校准',
    Description: '转向角度传感器校准',
    DateTime: '2023-11-01 13:15:22'
  },
  {
    Id: 7,
    SystemName: '捷豹路虎ESP系统',
    Device: 'ECU_003',
    Group1: '执行器',
    Group2: '制动系统',
    Group3: '右后轮',
    UserName: 'user2',
    UserLevel: '操作员',
    OldEvent: '故障',
    NewEvent: '正常',
    Description: '右后轮制动压力传感器更换并恢复正常',
    DateTime: '2023-11-01 14:50:10'
  },
  {
    Id: 8,
    SystemName: '捷豹路虎ESP系统',
    Device: 'ECU_005',
    Group1: '电源',
    Group2: '电池管理',
    Group3: '主电源',
    UserName: 'user3',
    UserLevel: '维护人员',
    OldEvent: '正常',
    NewEvent: '警告',
    Description: '系统电压偏低',
    DateTime: '2023-11-01 15:30:45'
  },
  {
    Id: 9,
    SystemName: '捷豹路虎ESP系统',
    Device: 'ECU_001',
    Group1: '控制模块',
    Group2: '安全系统',
    Group3: 'ESP功能',
    UserName: 'admin',
    UserLevel: '管理员',
    OldEvent: '系统配置更新',
    NewEvent: '系统自检',
    Description: '系统例行自检',
    DateTime: '2023-11-01 16:20:33'
  },
  {
    Id: 10,
    SystemName: '捷豹路虎ESP系统',
    Device: 'ECU_005',
    Group1: '电源',
    Group2: '电池管理',
    Group3: '主电源',
    UserName: 'user3',
    UserLevel: '维护人员',
    OldEvent: '警告',
    NewEvent: '正常',
    Description: '系统电压恢复正常',
    DateTime: '2023-11-01 17:45:12'
  }
];

// 模拟后端API响应
export function mockApiResponse(page, pageSize, filters = {}) {
  let filteredData = [...mockLogData];
  
  // 应用过滤条件
  if (filters.systemName) {
    filteredData = filteredData.filter(item => 
      item.SystemName.includes(filters.systemName)
    );
  }
  
  if (filters.device) {
    filteredData = filteredData.filter(item => 
      item.Device.includes(filters.device)
    );
  }
  
  if (filters.group1) {
    filteredData = filteredData.filter(item => 
      item.Group1.includes(filters.group1)
    );
  }
  
  if (filters.group2) {
    filteredData = filteredData.filter(item => 
      item.Group2.includes(filters.group2)
    );
  }
  
  if (filters.group3) {
    filteredData = filteredData.filter(item => 
      item.Group3.includes(filters.group3)
    );
  }
  
  if (filters.userName) {
    filteredData = filteredData.filter(item => 
      item.UserName.includes(filters.userName)
    );
  }
  
  if (filters.userLevel) {
    filteredData = filteredData.filter(item => 
      item.UserLevel.includes(filters.userLevel)
    );
  }
  
  if (filters.oldEvent) {
    filteredData = filteredData.filter(item => 
      item.OldEvent.includes(filters.oldEvent)
    );
  }
  
  if (filters.newEvent) {
    filteredData = filteredData.filter(item => 
      item.NewEvent.includes(filters.newEvent)
    );
  }
  
  if (filters.eventName) {
    filteredData = filteredData.filter(item => 
      item.OldEvent.includes(filters.eventName) || 
      item.NewEvent.includes(filters.eventName) ||
      item.Description.includes(filters.eventName)
    );
  }
  
  if (filters.description) {
    filteredData = filteredData.filter(item => 
      item.Description.includes(filters.description)
    );
  }
  if (filters.startDate) {
    filteredData = filteredData.filter(item => 
      item.DateTime >= filters.startDate
    );
  }
  
  if (filters.endDate) {
    filteredData = filteredData.filter(item => 
      item.DateTime <= filters.endDate
    );
  }
  
  // 分页
  const total = filteredData.length;
  const startIndex = (page - 1) * pageSize;
  const endIndex = startIndex + pageSize;
  const paginatedData = filteredData.slice(startIndex, endIndex);
  
  return {
    data: paginatedData,
    total,
    page,
    pageSize,
    totalPages: Math.ceil(total / pageSize)
  };
}